/**
 * 
 */
package uk.ac.ebi.curtain.utils.file.impl;

import java.io.IOException;

import uk.ac.ebi.curtain.utils.file.EntryMapper;
import uk.ac.ebi.curtain.utils.file.FileInfo;
import uk.ac.ebi.curtain.utils.file.ParseUtil;
import uk.ac.ebi.curtain.utils.io.ParseException;
import uk.ac.ebi.curtain.utils.io.impl.BufferedRaf;
import uk.ac.ebi.curtain.utils.io.impl.FileIO;

/**
 * @author mhaimel
 *
 */
public abstract class AbstractParser implements ParseUtil {

	@Override
	public void parse(FileInfo fileInfo,EntryMapper mapper) throws ParseException{
		BufferedRaf in = null;
		try {
			FileIO io = new FileIO(fileInfo.getFile());
			in = io.getBufferedRafReader();
			parse(in,fileInfo,mapper);
		} catch (IOException e) {
			throw new ParseException("Problems reading File " + fileInfo,e);
		} finally{
			FileIO.closeQuietly(in);
		}				
	}
	
	@Override
	public void parse(BufferedRaf in, FileInfo info, EntryMapper mapper)throws IOException {
		parseNEntry(-1, in, info, mapper);
	}

}
